﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;
namespace Zor_Bll
{
   public class Sys_Users_Bll<T> where T : class
    {
        /// <summary>
        /// 根据用户Id查询数据
        /// create zhl by 17-3-26
        /// </summary>
        /// <returns></returns>
        ///      
       public static List<T> SelectDepartmentTree()
       {
           return Sys_Users_DAL<T>.SelectDepartmentTree();
       }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(int index, out int TotalCount, string where)
        {
            return PagerHelp<T>.GetPagerList(index, "V_Sys_Users", "User_Id", out TotalCount, "IsDeleted=1 and Is_Available=1");
        }
   
        /// <summary>
        /// 根据用户Id查询数据
        /// create zhl by 2017.3.24
        /// </summary>
        /// <returns></returns>
        ///      
        public static T SelectPageListId(string user_Id)
        {
            return Sys_Users_DAL<T>.SelectPageListId(user_Id);
        }
        /// <summary>
        /// 查询所有权限Id和Name 
        /// create zhl by 2017.3.24
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectRols()
        {
            return Sys_Users_DAL<T>.SelectRols();
        }

        /// <summary>
        /// 用户管理-新增
        /// create zhl by 2017.3.24
        /// </summary>
        /// <param name="sysuser">用户对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer Insertsysusers(Sys_Users sysuser)
        {
            sysuser.User_Password = MD5Helper.StringToMD5("123456");
            sysuser.User_CreateDate = TimeHelper.ToTimeStamp(DateTime.Now);
            sysuser.User_CreateName = RequestSession.GetSessionUser().User_Id;
            BaseAnswer bar = Sys_Users_DAL<T>.Insertsysusers(sysuser);           
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "增加失败,请检查用户是否重复！";
            return bar;      


        }

        /// <summary>
        /// 用户管理-修改
        /// create zhl by 2017.3.24
        /// </summary>
        /// <param name="sysuser">用户对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer Updatesysusers(Sys_Users sysuser)
        {
            BaseAnswer bar = Sys_Users_DAL<T>.Updatesysusers(sysuser);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查用户是否重复！";
            return bar;        
        }
        /// <summary>
        /// 删除用户
        /// create zhl by 2017.3.24
        /// </summary>
        /// <param name="id">删除用户的id</param>
        /// <returns>1正常 返回0</returns>
        public static BaseAnswer Deletesysusers(int[] id)
        {
            BaseAnswer bar = Sys_Users_DAL<T>.Deletesysusers(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "设置成功！" : "设置失败！";
            return bar;
          
        }

        /// <summary>
        /// 设置账户为可用
        /// <param name="id">修改用户的id</param>
        /// </summary>
        /// <returns></returns>
        public static BaseAnswer UnlockUser(int[] id)
        {          
            BaseAnswer bar = Sys_Users_DAL<T>.UnlockUser(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "设置成功！" : "设置失败！";
            return bar;
          
        }


    }
}
